package com.meichis.yndms.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.meichis.yndms.R;
import com.meichis.yndms.adapter.StayInOrderDetailAdapter;
import com.meichis.yndms.common.MCode;
import com.meichis.yndms.databinding.ActivityStayInOrderDetailBinding;
import com.meichis.yndms.model.StayInOrder;
import com.meichis.yndms.ui.common.BaseActivity;

public class StayInOrderDetailActivity extends BaseActivity {

    private ActivityStayInOrderDetailBinding binding;
    private StayInOrderDetailAdapter adapter;


    @Override
    protected void setDataBindingContentView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_stay_in_order_detail);
        binding.setLifecycleOwner(this);
    }

    @Override
    protected void init() {
        binding.navigation.txtTitle.setText("在途订单明细");
        binding.navigation.navBack.setOnClickListener(v -> onBackPressed());

        StayInOrder order = (StayInOrder) getIntent().getSerializableExtra(MCode.STAYINORDER);
        binding.tvCode.setText(order.getOrderNo());
        binding.tvFrom.setText(order.getRepositoryName());
        binding.tvArrival.setText(order.getStorageName());
        binding.tvTime.setText(order.getOutDt());
        binding.tvName.setText(order.getDriverName() + " " + order.getMobile());
        binding.tvCount.setText(order.getQuantity() + "件");
        binding.tvWeight.setText(order.getWeight() + "吨");

        adapter = new StayInOrderDetailAdapter(this, R.layout.item_stay_in_order_detail, order.getItems());
        binding.rc.setLayoutManager(new LinearLayoutManager(this));
        binding.rc.setAdapter(adapter);

        binding.tvCode.setOnClickListener(v -> {
            ClipboardManager manager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData mClipData = ClipData.newPlainText("Label", order.getOrderNo());
            manager.setPrimaryClip(mClipData);
            showMsg("订单编号复制成功");
        });

        binding.tvName.setOnClickListener(v -> {
            Intent Intent = new Intent(android.content.Intent.ACTION_DIAL, Uri.parse("tel:" + order.getMobile()));
            startActivity(Intent);
        });
    }


}
